package com.anosine.gpsl.android.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.anosine.gpsl.android.R;
import com.anosine.gpsl.android.entity.Consumer;
import com.anosine.gpsl.android.entity.Login;
import com.anosine.gpsl.android.presenter.BasePresenterActivity;
import com.anosine.gpsl.android.presenter.ConsumerPresenter;
import com.anosine.gpsl.android.ui.ConsumerView;
import com.anosine.gpsl.android.util.StringUtil;
import com.anosine.gpsl.android.util.UserInfoProxy;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.lidroid.xutils.ViewUtils;
/**
 * @Title: UserInfoActivity
 * @Package com.anosine.gpsl.android.ui.activity
 * @Description: 个人信息界面
 * @author: sunny
 * @date: 2015-11-24
 * @version V1.0
 */
public class UserInfoActivity extends BasePresenterActivity implements
		ConsumerView {
	@ViewInject(R.id.content_tv_title)
	TextView title;
	@ViewInject(R.id.tv_show_userInfo)
	TextView mTvInfo;

	/**
	 * @Title: BackOnClick(View v)
	 * @Description: 返回按钮的点击事件，点击关闭当前activity
	 * @param: View v
	 * @return: 无
	 * @throws
	 */
	@OnClick(R.id.button_left)
	private void BackOnClick(View v) {
		finish();
	}
	/**
	 * @Title: onCreate(Bundle savedInstanceState)
	 * @Description: 初始化activity
	 * @param: Bundle savedInstanceState
	 * @return: 无
	 * @throws
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_userinfo);
		ViewUtils.inject(this);
		initViews();
	}
	/**
	 * @Title: initViews()
	 * @Description: 初始化view
	 * @param: 无
	 * @return: 无
	 * @throws
	 */
	protected void initViews() {
		title.setText("个人信息");
		initActivityOfConsumerInfo();
	}
	/**
	 * @Title: initActivityOfConsumerInfo()
	 * @Description: 调用个人信息接口
	 * @param: 无
	 * @return: 无
	 * @throws
	 */
	private void initActivityOfConsumerInfo() {
		// 将合成的URL传给服务器
		ConsumerPresenter presenter = new ConsumerPresenter(this);
		Login info = UserInfoProxy.getInstance().getLoginInfo();
		presenter.loadConsumer(info.userMd5);

	}
	/**
	 * @Title: setConsumer(Consumer t)
	 * @Description: 获取个人信息接口返回值
	 * @param: Consumer 个人信息实体类
	 * @return: 无
	 * @throws
	 */
	@Override
	public void setConsumer(Consumer t) {
		if (t != null) {
			StringBuffer sb = new StringBuffer();
			if (StringUtil.isNotEmpty(t.holdname)) {
				sb.append("客户名称：").append(t.holdname).append("\n");
			}
			if (StringUtil.isNotEmpty(t.consumptionmoney)) {
				sb.append("累计金额：").append(t.consumptionmoney).append("\n");
			}
			if (StringUtil.isNotEmpty(t.consumptionintegral)) {
				sb.append("累计积分：").append(t.consumptionintegral).append("\n");
			}
			if (StringUtil.isNotEmpty(t.starttime)) {
				sb.append("服务开始时间：").append(t.starttime).append("\n");
			}
			if (StringUtil.isNotEmpty(t.endtime)) {
				sb.append("保修到期时间：").append(t.endtime).append("\n");
			}
			if (StringUtil.isNotEmpty(t.simstarttime)) {
				sb.append("流量开始时间：").append(t.simstarttime).append("\n");
			}
			if (StringUtil.isNotEmpty(t.simendtime)) {
				sb.append("流量截止时间：").append(t.simendtime).append("\n");
			}

			mTvInfo.setText(sb.toString());
		}
	}
}
